package com.google.android.gcm.demo.server;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet that receives the request client makes after it receives a notification
 */
public class TokenReceivedServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private static final String PARAMETER_TOKEN = "token";
	  private static final String PARAMETER_REG_ID = "regId";


	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		long token = Long.valueOf(getParameter(request, PARAMETER_TOKEN));
		String regId = getParameter(request, PARAMETER_REG_ID);
		Datastore.getTokens().addResponseReceived(token, regId);
		setSuccess(response);
	}
}
